package Demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-06-03
 * Time: 18:08
 */
class Demo<T>{
    private Object[] array = new Object[10];

    public T getArray(int pos) {
        return T[pos];
    }

    public void setArray(int pos,Object val) {
        this.array[pos] = val;
    }
}
public class Test {
    public static void main(String[] args) {

    }
    public static void main3(String[] args) {
        Demo demo = new Demo();
        demo.setArray(0,1);
        demo.setArray(1,3.14);
        demo.setArray(2,"hao");
        demo.setArray(3,true);
        String val = (String)demo.getArray(2);
        int val1 = (int)demo.getArray(0);
        System.out.println(demo.getArray(0));
        System.out.println(demo.getArray(1));
        System.out.println(demo.getArray(2));
        System.out.println(demo.getArray(3));
        //暴露出来的问题
        //1.数组里面什么类型都可以存
        //2.每次拿出来的数据都要就行类型转化
    }
    public static void main2(String[] args) {
        Integer a = 127;//隐式装箱
      //Integer a = Integer.valueOf(a);
        Integer b = 127;
        Integer c = 128;
        Integer d = 128;
        System.out.println(a == b);
        System.out.println(c == d);//超出范围/会new一个对象
    }
    public static void main1(String[] args) {

        //装箱：将基本数据类型转换成包装类类型
        int val1 = 200;
        Integer val2 = Integer.valueOf(val1);//显示装箱
        System.out.println(val1);
        System.out.println(val2);
        Integer val3 = 300;//隐式装箱(底层会调用valueOf方法进行转换)
        System.out.println(val3);

        //拆箱：将包装类类型转换为基本数据类型
        Integer val4 = 400;
        int val5 = val4.intValue();//显示拆箱
        System.out.println(val5);
        Integer val6 = 90;
        int val7 = val6;//隐式拆箱
        System.out.println(val6);

        double val8 = val4.doubleValue();
        System.out.println(val8);
        float val9 = val4.floatValue();
        System.out.println(val9);
    }
}
